<?
global $db;
$query = $params["query"];
$r = $db->query("select * from wiki where ".
	" content like ".$db->sqlstring("%$query%").
	" and latest = 1 ".
	" order by datetimeon desc ".
	"");
	
echo "<table>";
#echo "<tr><th>page";#<th>datetimeon";
$pquery = preg_quote($query,"/");
$n = 1;
foreach ($r as $e) {
	echo "<tr>";
	#echo "<td valign=top>$n."; 
	echo "<td valign=top><a href=\"view.php?link={$e["link"]}\">{$e["title"]}</a>";
	
	echo "<tr>"; #NOTE: this highlighting doesn't always work, but it shows the right stuff...
	if (preg_match("/.{0,128}$pquery.{0,128}/si",$e["content"],$m)) {
		echo "<td valign=top>".preg_replace("/($pquery)/i","<span class='term'>$1</span>",htmlentities(strip_tags($m[0])));
		}
	echo "<tr><td>&nbsp;";

	$n++;
	}
echo "</table>";
?>